package org.tankwar.model;

import org.tankwar.util.GlobalUtil;
import org.tankwar.util.ImageUtil;
import org.tankwar.view.GamePanel;

import java.awt.*;

public class BombTank implements GameComponent{
    private final int x, y;
    private boolean live = true; // 初始状态为活着
    private final GamePanel tc;

    private static final Image[] images = { // 存储爆炸图片（从小到大的爆炸效果图）
            GlobalUtil.tk.getImage(BombTank.class.getResource(ImageUtil.BOOM1_IMAGE_URL)),
            GlobalUtil.tk.getImage(BombTank.class.getResource(ImageUtil.BOOM2_IMAGE_URL)),
            GlobalUtil.tk.getImage(BombTank.class.getResource(ImageUtil.BOOM3_IMAGE_URL)),
            GlobalUtil.tk.getImage(BombTank.class.getResource(ImageUtil.BOOM4_IMAGE_URL)),
            GlobalUtil.tk.getImage(BombTank.class.getResource(ImageUtil.BOOM5_IMAGE_URL)),
            GlobalUtil.tk.getImage(BombTank.class.getResource(ImageUtil.BOOM6_IMAGE_URL)),
            GlobalUtil.tk.getImage(BombTank.class.getResource(ImageUtil.BOOM7_IMAGE_URL)),
            GlobalUtil.tk.getImage(BombTank.class.getResource(ImageUtil.BOOM8_IMAGE_URL)),
            GlobalUtil.tk.getImage(BombTank.class.getResource(ImageUtil.BOOM9_IMAGE_URL)),
            GlobalUtil.tk.getImage(BombTank.class.getResource(ImageUtil.BOOM10_IMAGE_URL)), };
    int step = 0;

    public BombTank(int x, int y, GamePanel tc) { // 构造函数
        this.x = x;
        this.y = y;
        this.tc = tc;
    }
    @Override
    public void draw(Graphics g) { // 画出爆炸图像
        if (!live) { // 坦克消失后删除爆炸图
            tc.bombTanks.remove(this);
            return;
        }
        if (step == images.length) {
            live = false;
            step = 0;
            return;
        }
        g.drawImage(images[step], x, y, null);
        step++;
    }

    @Override
    public Rectangle getRect() {
        return null;
    }
}
